package com.kbt.listener;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import com.kbt.activity.LoginActivity;
import com.kbt.base.BaseApplication;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhgk
 * @package: com.kbt.listener
 * @TODO: 打开Activity事件并接收结果
 * @data: 2015/8/15 14:57
 * @version: V1.0
 */
public class ClickFragmentStartActForResultListenerCopy implements View.OnClickListener {

    private Class target;
    private int request_code;
    private Map<String, Object> params;
    private Fragment fragment;


    public ClickFragmentStartActForResultListenerCopy(Fragment fragment, Class _target, int _requst_code, Map params) {
        this.fragment = fragment;
        this.target = _target;
        this.request_code = _requst_code;
        //参数为空时新建
        this.params = params != null ? params : new HashMap<String, Object>();
    }

    /*********
     * 点击按钮打开Activity
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
            Intent intent = new Intent(v.getContext(), target);
            Bundle bl = new Bundle();
            //处理参数

            for (Map.Entry<String, Object> entry : params.entrySet()) {
                bl.putSerializable(entry.getKey(), (Serializable) entry.getValue());
            }
            intent.putExtra("bundle", bl);
            fragment.startActivityForResult(intent, request_code);
    }
}
